package com.example.administrator.yuejian35.Club.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian35.Club.activity.ClubInfoActivity;
import com.example.administrator.yuejian35.Club.bean.Club;
import com.example.administrator.yuejian35.Club.fragment.viewholder.ClubItemViewHolder;
import com.example.administrator.yuejian35.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.administrator.yuejian35.Config.Img_URL;

/**
 * Created by HP on 2017/9/26.
 */

public class ClubListAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<Club> clubList=new ArrayList<>();

    public ClubListAdapter(Context c, List<Club> clubList){
        this.context = c;
        this.clubList.addAll(clubList);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //1)  将item.xml 生成 itemView  -  View
        //2)  生成MyViewHolderd对象
        View itemView = LayoutInflater.from(context).inflate(R.layout.item_club,parent,false);
        ClubItemViewHolder holder = new ClubItemViewHolder(itemView);
        return holder;
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        //用于绑定数据
        //转换类型
        ClubItemViewHolder clubItemViewHolder= (ClubItemViewHolder) holder;

        clubItemViewHolder.club_address.setText("地址："+clubList.get(position).getAddress());
        clubItemViewHolder.club_name.setText(clubList.get(position).getClubname());
        /*int num= Integer.parseInt(clubList.get(position).getClubid());*/
        int num=position;
        if(num<3){

            clubItemViewHolder.club_name.setTextColor(0xFFff6762);
            clubItemViewHolder.itemView.setBackgroundColor(0xFFf8fdfd);
        }
        clubItemViewHolder.r.setRating(Float.parseFloat(clubList.get(position).getRate()));
        clubItemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,ClubInfoActivity.class);
                intent.putExtra("clubid",clubList.get(position).getClubid());
                context.startActivity(intent);
            }
        });
        Picasso.with(context)
                .load(Img_URL+clubList.get(position).getClubpic())
                .into(ClubItemViewHolder.club_pic);

    }

    @Override
    public int getItemCount() {
        return clubList.size();
    }
}

